import random

import redis
import requests

def should_request(url):
    client =redis.Redis(host='localhost',port=6379,db=0)
    urls = client.lrange('requests_urls',0,-1)
    return url.encode() in urls


def save_url(url):
    client = redis.Redis(host='localhost', port=6379, db=0)
    client.lpush('requests_urls', url)
    client.close()


def main():
    urls = [f'https://httpbin.org/get?age={random.randint(1,100)}' for i in range(10)]
    url = set(urls)
    for url in urls:
        if not should_request(url):
            res = requests.get(url)
            print(res)
            save_url(url)
        else:
            print('该地址已经请求过了')

main()
